package top.xana.acg.anime.inject

import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import okhttp3.OkHttpClient
import top.xana.acg.anime.network.AnimeApi
import top.xana.acg.anime.network.interceptor.HttpRequestInterceptor
import java.util.concurrent.TimeUnit
import javax.inject.Singleton

/**
 * @author xana
 * @date 2022/10/30 0030 12:44
 * @email cv4096@qq.com
 **/

@Module
@InstallIn(SingletonComponent::class)
object NetworkModule {

    @Provides
    @Singleton
    fun provideOkHttpClient(): OkHttpClient {
        return OkHttpClient.Builder()
            .addInterceptor(HttpRequestInterceptor())
            .connectTimeout(30, TimeUnit.SECONDS)
            .readTimeout(30, TimeUnit.SECONDS)
            .writeTimeout(30, TimeUnit.SECONDS)
            .build()
    }

    @Provides
    @Singleton
    fun provideAnimeApi() = AnimeApi()

}